package map;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
public class MapMain {
	public static void main(String[] args){
		//建立哈希表 并添加值
		Map map = new HashMap();
		map.put("Lucy",5);
		map.put("Lily",4);
		map.put("Han Meimei",5);
		map.put("Jim",3);
		map.put("Zou Encen",3);
		//查找lucy对应的值
		String namekey = "Lucy";
		Integer levelvalue = null;

		if (map.containsKey(namekey)){
			levelvalue = (Integer) map.get(namekey);
			System.out.println("Use namekey:" + namekey + " find levelvalue:" + levelvalue);
			System.out.println("-----------------------");
		}
		else
		{
			System.out.println("Does not contain namekey:" + namekey);
			System.out.println("-----------------------");
		}
		namekey = "Zou Encen";
		if (map.containsKey(namekey)){
			levelvalue = (Integer) map.get(namekey);
			System.out.println("Use namekey:" + namekey + " find levelvalue:" + levelvalue);
			System.out.println("-----------------------");
		}
		else
		{
			System.out.println("Does not contain namekey:" + namekey);
			System.out.println("-----------------------");
		}

		namekey = "zhanshan";
		if (map.containsKey(namekey)){
			levelvalue = (Integer) map.get(namekey);
			System.out.println("Use namekey:" + namekey + " find levelvalue:" + levelvalue);
			System.out.println("-----------------------");
		}
		else
		{
			System.out.println("Does not contain namekey:" + namekey);
			System.out.println("-----------------------");
		}

		//entrySet()方法返回此映射所包含的映射关系的 Set 视图。
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
		    //Map.Entry 对象仅在迭代期间有效
            Map.Entry entry = (Map.Entry) it.next();
            namekey = (String) entry.getKey();
            levelvalue = (Integer) entry.getValue();
            System.out.println("Use iterator to get the first entry is nameKey :" + namekey + "  levelValue :" + levelvalue);
            System.out.println("-----------------------");
        }
	}
}
